package com.gpframework.module.controller.ctn;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.core.page.TableDataInfo;
import com.gpframework.module.ctn.domain.GpHoldGoodsChinaRelease;
import com.gpframework.module.ctn.domain.req.GpHoldGoodsChinaReleaseAdd;
import com.gpframework.module.ctn.domain.req.GpHoldGoodsChinaReleaseReq;
import com.gpframework.module.ctn.domain.req.GpHoldGoodsChinaReleaseUpdate;
import com.gpframework.module.ctn.domain.vo.GpHoldGoodsChinaReleaseVo;
import com.gpframework.module.ctn.service.IGpHoldGoodsChinaReleaseService;
import com.gpframework.module.ctn.service.IGpNigeriaWarehouseReleaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
/**
 * @ClassName GpHoldGoodsChinaReleaseController
 * @Author gpframework
 * @Date 2024-01-08
 * @Version 1.0.0
 * @Description 扣货国内放货Controller 接口类
 */
@Validated
@Api(tags = "扣货国内放货")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/ctn/goodschinarelease" )
public class GpHoldGoodsChinaReleaseController extends BaseController {

    private final IGpHoldGoodsChinaReleaseService iGpHoldGoodsChinaReleaseService;

    private final IGpNigeriaWarehouseReleaseService iGpNigeriaWarehouseReleaseService;

 /**
  * @Description 分页
  * @Author gpframework
  * @Date 2024-01-08
  * @Param gpHoldGoodsChinaRelease
  * @Return TableDataInfo
 */
    @ApiOperation("列表")
    @GetMapping("/list")
    public TableDataInfo<GpHoldGoodsChinaReleaseVo> list(GpHoldGoodsChinaReleaseReq gpHoldGoodsChinaReleaseReq)
    {
        startPage();
        QueryWrapper<GpHoldGoodsChinaRelease> lqw = new QueryWrapper<GpHoldGoodsChinaRelease>();
        gpHoldGoodsChinaReleaseReq.generatorQuery(lqw,true);
        List<GpHoldGoodsChinaReleaseVo> list = iGpHoldGoodsChinaReleaseService.listVo(lqw);
        return getDataTable(list);
    }

    /**
     * @Description 详情
     * @Author gpframework
     * @Date 2024-01-08
     * @Param gpHoldGoodsChinaRelease
     * @Return AjaxResult
     */
    @ApiOperation("详情")
    @GetMapping(value = "/{id}" )
    public AjaxResult<GpHoldGoodsChinaReleaseVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iGpHoldGoodsChinaReleaseService.getVoById(id));
    }

    /**
     * @Description 新增
     * @Author gpframework
     * @Date 2024-01-08
     * @Param gpHoldGoodsChinaRelease
     * @Return AjaxResult
     */
    @ApiOperation("新增")
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GpHoldGoodsChinaReleaseAdd gpHoldGoodsChinaReleaseAdd) {
        GpHoldGoodsChinaRelease gpHoldGoodsChinaRelease = Convert.convert(new TypeReference<GpHoldGoodsChinaRelease>() {}, gpHoldGoodsChinaReleaseAdd);
        if (gpHoldGoodsChinaReleaseAdd.getHoldGoodsChinaReleaseId()==null){
            return toAjax(iGpHoldGoodsChinaReleaseService.save(gpHoldGoodsChinaRelease) ? 1 : 0);
        }
        gpHoldGoodsChinaRelease.setId(gpHoldGoodsChinaReleaseAdd.getHoldGoodsChinaReleaseId());
        return toAjax(iGpHoldGoodsChinaReleaseService.updateById(gpHoldGoodsChinaRelease) ? 1 : 0);
    }

    /**
     * @Description 修改
     * @Author gpframework
     * @Date 2024-01-08
     * @Param gpHoldGoodsChinaRelease
     * @Return AjaxResult
     */
    @ApiOperation("修改")
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody GpHoldGoodsChinaReleaseUpdate gpHoldGoodsChinaReleaseUpdate) {
        GpHoldGoodsChinaRelease gpHoldGoodsChinaRelease = Convert.convert(new TypeReference<GpHoldGoodsChinaRelease>() {}, gpHoldGoodsChinaReleaseUpdate);
        return toAjax(iGpHoldGoodsChinaReleaseService.updateById(gpHoldGoodsChinaRelease) ? 1 : 0);
    }

    /**
     * @Description 删除
     * @Author gpframework
     * @Date 2024-01-08
     * @Param gpHoldGoodsChinaRelease
     * @Return AjaxResult
     */
    @ApiOperation("删除")
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iGpHoldGoodsChinaReleaseService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
